package com.mypage.adapter;


import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;

import com.cloudcc.mobile.R;
import com.cloudcc.mobile.entity.beau.BeauRecordTypeEntity;

import java.util.HashMap;
import java.util.List;

    /**
     * Created by liuyongjie on 2017/5/17.
     */

    public class RecorderAdapter extends BaseAdapter {
        public List<BeauRecordTypeEntity.DataBean> mxList;
        public Context context;
        // 用来控制CheckBox的选中状况
        private static HashMap<Integer,Boolean> isSelected;
        public RecorderAdapter(Context context, List<BeauRecordTypeEntity.DataBean> mxList) {
        this.mxList = mxList;
        this.context = context;
        isSelected = new HashMap<Integer, Boolean>();
        initDate();
    }
//         初始化isSelected的数据
        private void initDate(){
            for(int i=0; i<mxList.size();i++) {
                getIsSelected().put(i,false);
            }
        }
        @Override
        public int getCount() {
            return mxList.size()==0?0:mxList.size();
        }

        @Override
        public Object getItem(int position) {
            return mxList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder h = null;
            if (convertView==null){
                h = new ViewHolder();
                convertView = View.inflate(context, R.layout.change_reocoder_type_item,null);
                h.checkBox = (CheckBox) convertView.findViewById(R.id.checkBox);
                convertView.setTag(h);
            }else{
                h = (ViewHolder) convertView.getTag();
            }
            if("true".equals(mxList.get(position).getIsdefault())) {
                h.checkBox.setChecked(true);
            }

            h.checkBox.setText("  "+String.valueOf(mxList.get(position).getName()));
//        if (mType.equals(mList.get(position).Id)){
//            h.checkBox.setChecked(true);
//        }
            h.checkBox.setChecked(getIsSelected().get(position));
            return convertView;
        }
        public class ViewHolder{
            public CheckBox checkBox;
        }
        public static HashMap<Integer,Boolean> getIsSelected() {
            return isSelected;
        }
        public static void setIsSelected(HashMap<Integer,Boolean> isSelected) {
            RecorderAdapter.isSelected = isSelected;
        }
    }


